package com.jt.tenant.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetTravelByDate;

import java.util.List;

/**
 * Created by Administrator on 2016/2/14.
 */
public abstract class TrackAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;

    private List<GetTravelByDate.Travel> list;

    public TrackAdapter(Context context,List<GetTravelByDate.Travel> list){

        this.layoutInflater = ((Activity)context).getLayoutInflater();

        this.list = list;

    }

    @Override
    public int getCount() {

        return list.size();

    }

    @Override
    public Object getItem(int position) {

        return null;

    }

    @Override
    public long getItemId(int position) {

        return 0;

    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;

        if (convertView == null){

            convertView = JTApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_track, null));

            holder = new ViewHolder();

            holder.trackname = (TextView) convertView.findViewById(R.id.track_name);

            holder.tracktime = (TextView) convertView.findViewById(R.id.track_time);

            holder.trackmileage = (TextView) convertView.findViewById(R.id.track_mileage);

            convertView.setTag(holder);


        }else{

            holder = (ViewHolder) convertView.getTag();


        }

        holder.trackname.setText(list.get(position).START_NAME+"至"+list.get(position).END_NAME);

        holder.tracktime.setText(list.get(position).START_TIME+"-"+list.get(position).END_TIME);

        holder.trackmileage.setText("里程: "+ list.get(position).MILEAGE+"公里");

        return convertView;

    }

    private class ViewHolder {

        private TextView trackname;

        private TextView tracktime;

        private TextView trackmileage;
    }

    protected abstract void onClose(String s);

}
